#ifndef SERVICEENTR_H
#define SERVICEENTR_H
#include "HttpServer.hpp"
#include "file_utils.hpp"
#include "ThreadPool.hpp"
#include "json.hpp"
#include "ChatCinema.hpp"

using json = nlohmann::json;

class ServiceEntrance {
public:
    ServiceEntrance(HttpServer* server, ThreadPool* pool);
    ~ServiceEntrance()=default;

    // http对应路径处理函数
    // 图标
    void favicon(ConnectionPtr conn);
    void bird(ConnectionPtr conn);
    // 加入放映室等功能
    void main(ConnectionPtr conn);
    void createChatCinema(ConnectionPtr conn);
    void joinChatCinema(ConnectionPtr conn);
    void cinema(ConnectionPtr conn);
    void video(ConnectionPtr conn);

    // 升级为websocket
    void upgrade(ConnectionPtr conn);

    //websocket功能
    void onWebSocketMessage(ConnectionPtr conn);
    void addHistory(const std::string& username, const std::string& message, const std::string& roomname);
    bool addUserWebConn(const std::string& username, const std::string& roomName, ConnectionPtr conn);
    void broadcast(const std::string& username, const std::string& roomName, const std::string& message);

    //websocket关闭时的处理函数
    void onWebSocketClose(ConnectionPtr conn);

    // charRoom关闭时的处理函数
    void onRoomShutDown(const std::string& roomName);

    
    
    


private:
    HttpServer* server;
    ThreadPool* threadpool_;
    std::map<std::string, std::shared_ptr<ChatCinema>> chatRooms_;



};


#endif